// import { queryPeopleByIdOrcYgxm } from '@/api/staff'

const state = {
  // 可选择人员列表
  // {
  //   id: 1,
  //   cusernumb: '陈福铭',         //
  //   cYgxmsx: '福-铭'   // 人员缩写
  // },
  searchValue: '',
  isDeptAbbreviation: true, // 是否显示部门简称
  userList: [
    {
      id: 1,
      cygxm: '陈福铭',
      cYgxmsx: '福-铭',
      cusernumb: '1084870',
      cbmjc: '222'
    },
    {
      id: 2,
      cygxm: '王立刚',
      cYgxmsx: '立-刚',
      cusernumb: '1084871'
    },
    {
      id: 3,
      cygxm: '陈超',
      cYgxmsx: '陈-超',
      cusernumb: '1084872'
    },
    {
      id: 4,
      cygxm: '洪州',
      cYgxmsx: '洪-州',
      cusernumb: '1084873'
    },
    {
      id: 5,
      cygxm: '金丽君',
      cYgxmsx: '丽-君',
      cusernumb: '1084874'
    }
  ],
  checkUserList: [],
  departmentList: [
    {
      cusernumb: '光科',
      id: '1'
    },
    {
      cusernumb: '信息技术部',
      id: '2'
    }

  ],
  subDepartmentList: [
    {
      cusernumb: '软件开发课',
      id: '3'
    },
    {
      cusernumb: '综合服务数字化课',
      id: '4'
    }
  ],
  pagination: {
    page: 1,
    rows: 20,
    total: 0,
    show: false
  }
}
const actions = {
  init({ state }, data) {
  },
  getPeopleByDepetid({ state }, data) {
    state.userList = []
  },
  getSubDepartmentList({ state }, data) {
    alert(1)
  },
  // 根据工号或者名字查询用户
  queryPeopleByIdOrcYgxm({ state }, data) {
    return new Promise(async(resolve, reject) => {
      const jsonStr = {
        page: state.pagination.page,
        rows: state.pagination.rows,
        searchValue: state.searchValue
      }
      queryPeopleByIdOrcYgxm(jsonStr)
        .then(response => {
          state.userList = response.result
        })
        .catch(error => {
          reject(error)
        })
    })
  },
  setUserList({ state }, data) {
    state.userList = data
  },
  setcheckUserList({ state }, data) {
    state.checkUserList = data
  },
  // 下一页
  handleNext({ state, dispatch }, data) {
    state.pagination.page++
    dispatch('queryPeopleByIdOrcYgxm')
  },
  // 上一页
  handlePrev({ state, dispatch }, data) {
    state.pagination.page--
    dispatch('queryPeopleByIdOrcYgxm')
  },
  handleCurrentChange({ state, dispatch }, data) {
    state.pagination.page = data
    dispatch('queryPeopleByIdOrcYgxm')
  }
}

const mutations = {}

export default {
  cYgxmspaced: true,
  mutations,
  actions,
  state
}
